/****************************************************************************
 *Copyright(C),2024, Ningbo Tuopu Group Co., Ltd.
 *FileName:   MotAsp_Lib.c
 *Date:       2024-12-16 19:03:04
 *Author:     TianGui.Wang
 *Version:    0
 *Path:       
 *Description:
 ****************************************************************************/
/****************************************************************************/
/*                             Include area                                 */
/****************************************************************************/
/* PRQA S 0380++ # M3CM-2_2-C99:Dir-1.1-C99 Number of macro definitions exceeds 4095
 * Reason: RTE error doesn't need to be repaired.*/
#include "MotAsp/MotAsp_Lib.h"
/* PRQA S 0380--*/

/****************************************************************************/
/*                             Definition area                              */
/****************************************************************************/

/****************************************************************************/
/*                             Typedef area                                 */
/****************************************************************************/

/****************************************************************************/
/*                             Local data at RAM                            */
/****************************************************************************/
/* Arctan Table */
const uint16_T MOTASP_Lib_AtanTable[1024] = {
0x000Au,0x0014u,0x001Eu,0x0028u,0x0032u,0x003Du,0x0047u,0x0051u,
0x005Bu,0x0065u,0x0070u,0x007Au,0x0084u,0x008Eu,0x0098u,0x00A2u,
0x00ADu,0x00B7u,0x00C1u,0x00CBu,0x00D5u,0x00E0u,0x00EAu,0x00F4u,
0x00FEu,0x0108u,0x0112u,0x011Du,0x0127u,0x0131u,0x013Bu,0x0145u,
0x0150u,0x015Au,0x0164u,0x016Eu,0x0178u,0x0182u,0x018Du,0x0197u,
0x01A1u,0x01ABu,0x01B5u,0x01BFu,0x01CAu,0x01D4u,0x01DEu,0x01E8u,
0x01F2u,0x01FCu,0x0207u,0x0211u,0x021Bu,0x0225u,0x022Fu,0x0239u,
0x0243u,0x024Eu,0x0258u,0x0262u,0x026Cu,0x0276u,0x0280u,0x028Bu,
0x0295u,0x029Fu,0x02A9u,0x02B3u,0x02BDu,0x02C7u,0x02D2u,0x02DCu,
0x02E6u,0x02F0u,0x02FAu,0x0304u,0x030Eu,0x0318u,0x0323u,0x032Du,
0x0337u,0x0341u,0x034Bu,0x0355u,0x035Fu,0x0369u,0x0374u,0x037Eu,
0x0388u,0x0392u,0x039Cu,0x03A6u,0x03B0u,0x03BAu,0x03C4u,0x03CEu,
0x03D9u,0x03E3u,0x03EDu,0x03F7u,0x0401u,0x040Bu,0x0415u,0x041Fu,
0x0429u,0x0433u,0x043Du,0x0448u,0x0452u,0x045Cu,0x0466u,0x0470u,
0x047Au,0x0484u,0x048Eu,0x0498u,0x04A2u,0x04ACu,0x04B6u,0x04C0u,
0x04CAu,0x04D4u,0x04DEu,0x04E8u,0x04F2u,0x04FDu,0x0507u,0x0511u,
0x051Bu,0x0525u,0x052Fu,0x0539u,0x0543u,0x054Du,0x0557u,0x0561u,
0x056Bu,0x0575u,0x057Fu,0x0589u,0x0593u,0x059Du,0x05A7u,0x05B1u,
0x05BBu,0x05C5u,0x05CFu,0x05D9u,0x05E3u,0x05EDu,0x05F7u,0x0601u,
0x060Bu,0x0614u,0x061Eu,0x0628u,0x0632u,0x063Cu,0x0646u,0x0650u,
0x065Au,0x0664u,0x066Eu,0x0678u,0x0682u,0x068Cu,0x0696u,0x06A0u,
0x06AAu,0x06B3u,0x06BDu,0x06C7u,0x06D1u,0x06DBu,0x06E5u,0x06EFu,
0x06F9u,0x0703u,0x070Du,0x0716u,0x0720u,0x072Au,0x0734u,0x073Eu,
0x0748u,0x0752u,0x075Cu,0x0765u,0x076Fu,0x0779u,0x0783u,0x078Du,
0x0797u,0x07A0u,0x07AAu,0x07B4u,0x07BEu,0x07C8u,0x07D2u,0x07DBu,
0x07E5u,0x07EFu,0x07F9u,0x0803u,0x080Cu,0x0816u,0x0820u,0x082Au,
0x0834u,0x083Du,0x0847u,0x0851u,0x085Bu,0x0864u,0x086Eu,0x0878u,
0x0882u,0x088Bu,0x0895u,0x089Fu,0x08A9u,0x08B2u,0x08BCu,0x08C6u,
0x08CFu,0x08D9u,0x08E3u,0x08EDu,0x08F6u,0x0900u,0x090Au,0x0913u,
0x091Du,0x0927u,0x0930u,0x093Au,0x0944u,0x094Du,0x0957u,0x0961u,
0x096Au,0x0974u,0x097Eu,0x0987u,0x0991u,0x099Bu,0x09A4u,0x09AEu,
0x09B8u,0x09C1u,0x09CBu,0x09D4u,0x09DEu,0x09E8u,0x09F1u,0x09FBu,
0x0A04u,0x0A0Eu,0x0A17u,0x0A21u,0x0A2Bu,0x0A34u,0x0A3Eu,0x0A47u,
0x0A51u,0x0A5Au,0x0A64u,0x0A6Du,0x0A77u,0x0A80u,0x0A8Au,0x0A94u,
0x0A9Du,0x0AA7u,0x0AB0u,0x0ABAu,0x0AC3u,0x0ACDu,0x0AD6u,0x0AE0u,
0x0AE9u,0x0AF2u,0x0AFCu,0x0B05u,0x0B0Fu,0x0B18u,0x0B22u,0x0B2Bu,
0x0B35u,0x0B3Eu,0x0B47u,0x0B51u,0x0B5Au,0x0B64u,0x0B6Du,0x0B77u,
0x0B80u,0x0B89u,0x0B93u,0x0B9Cu,0x0BA5u,0x0BAFu,0x0BB8u,0x0BC2u,
0x0BCBu,0x0BD4u,0x0BDEu,0x0BE7u,0x0BF0u,0x0BFAu,0x0C03u,0x0C0Cu,
0x0C16u,0x0C1Fu,0x0C28u,0x0C32u,0x0C3Bu,0x0C44u,0x0C4Du,0x0C57u,
0x0C60u,0x0C69u,0x0C73u,0x0C7Cu,0x0C85u,0x0C8Eu,0x0C98u,0x0CA1u,
0x0CAAu,0x0CB3u,0x0CBCu,0x0CC6u,0x0CCFu,0x0CD8u,0x0CE1u,0x0CEBu,
0x0CF4u,0x0CFDu,0x0D06u,0x0D0Fu,0x0D18u,0x0D22u,0x0D2Bu,0x0D34u,
0x0D3Du,0x0D46u,0x0D4Fu,0x0D58u,0x0D62u,0x0D6Bu,0x0D74u,0x0D7Du,
0x0D86u,0x0D8Fu,0x0D98u,0x0DA1u,0x0DAAu,0x0DB4u,0x0DBDu,0x0DC6u,
0x0DCFu,0x0DD8u,0x0DE1u,0x0DEAu,0x0DF3u,0x0DFCu,0x0E05u,0x0E0Eu,
0x0E17u,0x0E20u,0x0E29u,0x0E32u,0x0E3Bu,0x0E44u,0x0E4Du,0x0E56u,
0x0E5Fu,0x0E68u,0x0E71u,0x0E7Au,0x0E83u,0x0E8Cu,0x0E95u,0x0E9Eu,
0x0EA7u,0x0EAFu,0x0EB8u,0x0EC1u,0x0ECAu,0x0ED3u,0x0EDCu,0x0EE5u,
0x0EEEu,0x0EF7u,0x0EFFu,0x0F08u,0x0F11u,0x0F1Au,0x0F23u,0x0F2Cu,
0x0F35u,0x0F3Du,0x0F46u,0x0F4Fu,0x0F58u,0x0F61u,0x0F69u,0x0F72u,
0x0F7Bu,0x0F84u,0x0F8Du,0x0F95u,0x0F9Eu,0x0FA7u,0x0FB0u,0x0FB8u,
0x0FC1u,0x0FCAu,0x0FD3u,0x0FDBu,0x0FE4u,0x0FEDu,0x0FF5u,0x0FFEu,
0x1007u,0x1010u,0x1018u,0x1021u,0x102Au,0x1032u,0x103Bu,0x1044u,
0x104Cu,0x1055u,0x105Du,0x1066u,0x106Fu,0x1077u,0x1080u,0x1089u,
0x1091u,0x109Au,0x10A2u,0x10ABu,0x10B3u,0x10BCu,0x10C5u,0x10CDu,
0x10D6u,0x10DEu,0x10E7u,0x10EFu,0x10F8u,0x1100u,0x1109u,0x1111u,
0x111Au,0x1122u,0x112Bu,0x1133u,0x113Cu,0x1144u,0x114Du,0x1155u,
0x115Eu,0x1166u,0x116Eu,0x1177u,0x117Fu,0x1188u,0x1190u,0x1199u,
0x11A1u,0x11A9u,0x11B2u,0x11BAu,0x11C2u,0x11CBu,0x11D3u,0x11DCu,
0x11E4u,0x11ECu,0x11F5u,0x11FDu,0x1205u,0x120Eu,0x1216u,0x121Eu,
0x1226u,0x122Fu,0x1237u,0x123Fu,0x1248u,0x1250u,0x1258u,0x1260u,
0x1269u,0x1271u,0x1279u,0x1281u,0x1289u,0x1292u,0x129Au,0x12A2u,
0x12AAu,0x12B3u,0x12BBu,0x12C3u,0x12CBu,0x12D3u,0x12DBu,0x12E4u,
0x12ECu,0x12F4u,0x12FCu,0x1304u,0x130Cu,0x1314u,0x131Cu,0x1325u,
0x132Du,0x1335u,0x133Du,0x1345u,0x134Du,0x1355u,0x135Du,0x1365u,
0x136Du,0x1375u,0x137Du,0x1385u,0x138Du,0x1395u,0x139Du,0x13A5u,
0x13ADu,0x13B5u,0x13BDu,0x13C5u,0x13CDu,0x13D5u,0x13DDu,0x13E5u,
0x13EDu,0x13F5u,0x13FDu,0x1405u,0x140Du,0x1415u,0x141Cu,0x1424u,
0x142Cu,0x1434u,0x143Cu,0x1444u,0x144Cu,0x1454u,0x145Bu,0x1463u,
0x146Bu,0x1473u,0x147Bu,0x1483u,0x148Au,0x1492u,0x149Au,0x14A2u,
0x14AAu,0x14B1u,0x14B9u,0x14C1u,0x14C9u,0x14D0u,0x14D8u,0x14E0u,
0x14E8u,0x14EFu,0x14F7u,0x14FFu,0x1507u,0x150Eu,0x1516u,0x151Eu,
0x1525u,0x152Du,0x1535u,0x153Cu,0x1544u,0x154Cu,0x1553u,0x155Bu,
0x1563u,0x156Au,0x1572u,0x1579u,0x1581u,0x1589u,0x1590u,0x1598u,
0x159Fu,0x15A7u,0x15AEu,0x15B6u,0x15BEu,0x15C5u,0x15CDu,0x15D4u,
0x15DCu,0x15E3u,0x15EBu,0x15F2u,0x15FAu,0x1601u,0x1609u,0x1610u,
0x1618u,0x161Fu,0x1627u,0x162Eu,0x1636u,0x163Du,0x1644u,0x164Cu,
0x1653u,0x165Bu,0x1662u,0x166Au,0x1671u,0x1678u,0x1680u,0x1687u,
0x168Eu,0x1696u,0x169Du,0x16A5u,0x16ACu,0x16B3u,0x16BBu,0x16C2u,
0x16C9u,0x16D1u,0x16D8u,0x16DFu,0x16E6u,0x16EEu,0x16F5u,0x16FCu,
0x1704u,0x170Bu,0x1712u,0x1719u,0x1721u,0x1728u,0x172Fu,0x1736u,
0x173Du,0x1745u,0x174Cu,0x1753u,0x175Au,0x1761u,0x1769u,0x1770u,
0x1777u,0x177Eu,0x1785u,0x178Cu,0x1794u,0x179Bu,0x17A2u,0x17A9u,
0x17B0u,0x17B7u,0x17BEu,0x17C5u,0x17CDu,0x17D4u,0x17DBu,0x17E2u,
0x17E9u,0x17F0u,0x17F7u,0x17FEu,0x1805u,0x180Cu,0x1813u,0x181Au,
0x1821u,0x1828u,0x182Fu,0x1836u,0x183Du,0x1844u,0x184Bu,0x1852u,
0x1859u,0x1860u,0x1867u,0x186Eu,0x1875u,0x187Cu,0x1883u,0x188Au,
0x1890u,0x1897u,0x189Eu,0x18A5u,0x18ACu,0x18B3u,0x18BAu,0x18C1u,
0x18C8u,0x18CEu,0x18D5u,0x18DCu,0x18E3u,0x18EAu,0x18F1u,0x18F7u,
0x18FEu,0x1905u,0x190Cu,0x1913u,0x1919u,0x1920u,0x1927u,0x192Eu,
0x1935u,0x193Bu,0x1942u,0x1949u,0x1950u,0x1956u,0x195Du,0x1964u,
0x196Au,0x1971u,0x1978u,0x197Fu,0x1985u,0x198Cu,0x1993u,0x1999u,
0x19A0u,0x19A7u,0x19ADu,0x19B4u,0x19BAu,0x19C1u,0x19C8u,0x19CEu,
0x19D5u,0x19DCu,0x19E2u,0x19E9u,0x19EFu,0x19F6u,0x19FDu,0x1A03u,
0x1A0Au,0x1A10u,0x1A17u,0x1A1Du,0x1A24u,0x1A2Au,0x1A31u,0x1A37u,
0x1A3Eu,0x1A44u,0x1A4Bu,0x1A51u,0x1A58u,0x1A5Eu,0x1A65u,0x1A6Bu,
0x1A72u,0x1A78u,0x1A7Fu,0x1A85u,0x1A8Cu,0x1A92u,0x1A99u,0x1A9Fu,
0x1AA5u,0x1AACu,0x1AB2u,0x1AB9u,0x1ABFu,0x1AC5u,0x1ACCu,0x1AD2u,
0x1AD9u,0x1ADFu,0x1AE5u,0x1AECu,0x1AF2u,0x1AF8u,0x1AFFu,0x1B05u,
0x1B0Bu,0x1B12u,0x1B18u,0x1B1Eu,0x1B25u,0x1B2Bu,0x1B31u,0x1B37u,
0x1B3Eu,0x1B44u,0x1B4Au,0x1B50u,0x1B57u,0x1B5Du,0x1B63u,0x1B69u,
0x1B70u,0x1B76u,0x1B7Cu,0x1B82u,0x1B88u,0x1B8Fu,0x1B95u,0x1B9Bu,
0x1BA1u,0x1BA7u,0x1BAEu,0x1BB4u,0x1BBAu,0x1BC0u,0x1BC6u,0x1BCCu,
0x1BD2u,0x1BD9u,0x1BDFu,0x1BE5u,0x1BEBu,0x1BF1u,0x1BF7u,0x1BFDu,
0x1C03u,0x1C09u,0x1C0Fu,0x1C16u,0x1C1Cu,0x1C22u,0x1C28u,0x1C2Eu,
0x1C34u,0x1C3Au,0x1C40u,0x1C46u,0x1C4Cu,0x1C52u,0x1C58u,0x1C5Eu,
0x1C64u,0x1C6Au,0x1C70u,0x1C76u,0x1C7Cu,0x1C82u,0x1C88u,0x1C8Eu,
0x1C94u,0x1C9Au,0x1CA0u,0x1CA5u,0x1CABu,0x1CB1u,0x1CB7u,0x1CBDu,
0x1CC3u,0x1CC9u,0x1CCFu,0x1CD5u,0x1CDBu,0x1CE0u,0x1CE6u,0x1CECu,
0x1CF2u,0x1CF8u,0x1CFEu,0x1D04u,0x1D09u,0x1D0Fu,0x1D15u,0x1D1Bu,
0x1D21u,0x1D26u,0x1D2Cu,0x1D32u,0x1D38u,0x1D3Eu,0x1D43u,0x1D49u,
0x1D4Fu,0x1D55u,0x1D5Au,0x1D60u,0x1D66u,0x1D6Cu,0x1D71u,0x1D77u,
0x1D7Du,0x1D83u,0x1D88u,0x1D8Eu,0x1D94u,0x1D99u,0x1D9Fu,0x1DA5u,
0x1DAAu,0x1DB0u,0x1DB6u,0x1DBBu,0x1DC1u,0x1DC7u,0x1DCCu,0x1DD2u,
0x1DD8u,0x1DDDu,0x1DE3u,0x1DE9u,0x1DEEu,0x1DF4u,0x1DF9u,0x1DFFu,
0x1E05u,0x1E0Au,0x1E10u,0x1E15u,0x1E1Bu,0x1E20u,0x1E26u,0x1E2Cu,
0x1E31u,0x1E37u,0x1E3Cu,0x1E42u,0x1E47u,0x1E4Du,0x1E52u,0x1E58u,
0x1E5Du,0x1E63u,0x1E68u,0x1E6Eu,0x1E73u,0x1E79u,0x1E7Eu,0x1E84u,
0x1E89u,0x1E8Fu,0x1E94u,0x1E99u,0x1E9Fu,0x1EA4u,0x1EAAu,0x1EAFu,
0x1EB5u,0x1EBAu,0x1EBFu,0x1EC5u,0x1ECAu,0x1ED0u,0x1ED5u,0x1EDAu,
0x1EE0u,0x1EE5u,0x1EEAu,0x1EF0u,0x1EF5u,0x1EFBu,0x1F00u,0x1F05u,
0x1F0Bu,0x1F10u,0x1F15u,0x1F1Bu,0x1F20u,0x1F25u,0x1F2Au,0x1F30u,
0x1F35u,0x1F3Au,0x1F40u,0x1F45u,0x1F4Au,0x1F4Fu,0x1F55u,0x1F5Au,
0x1F5Fu,0x1F64u,0x1F6Au,0x1F6Fu,0x1F74u,0x1F79u,0x1F7Fu,0x1F84u,
0x1F89u,0x1F8Eu,0x1F93u,0x1F99u,0x1F9Eu,0x1FA3u,0x1FA8u,0x1FADu,
0x1FB3u,0x1FB8u,0x1FBDu,0x1FC2u,0x1FC7u,0x1FCCu,0x1FD1u,0x1FD7u,
0x1FDCu,0x1FE1u,0x1FE6u,0x1FEBu,0x1FF0u,0x1FF5u,0x1FFAu,0x2000u
};
/****************************************************************************/
/*                             Global data at RAM                           */
/****************************************************************************/

/****************************************************************************/
/*                        Global data at RAM declare area                   */
/****************************************************************************/

/****************************************************************************/
/*                             Local data at ROM                            */
/****************************************************************************/

/****************************************************************************/
/*                             Global data at ROM                           */
/****************************************************************************/

/****************************************************************************/
/*                        Global data at ROM declare area                   */
/****************************************************************************/

/****************************************************************************/
/*                        Local function declare area                       */
/****************************************************************************/

/****************************************************************************/
/*                        Global function declare area                      */
/****************************************************************************/

/****************************************************************************/
/*                      Global function Implementation area                 */
/****************************************************************************/

/*
*Function :                                  MotAsp_Lib_Com_Avg_Mid                      
*Brief    :  The median value of the largest and smallest is calculated, and the callback is made                   
*Para     :                        MotAsp_Lib_SINCOS_LIMIT_DATA *MotAsp_Lib_Obj 
                                   typedef struct {
                                             sint16 Val;    -    The median value of the calculation
                                             sint16 Max;    -    maximum
                                             sint16 Min;    -    minmum
                                             }MotAsp_Lib_SINCOS_LIMIT_DATA;                       
*Return   :                                          NULL                                
 */
void MotAsp_Lib_Com_Avg_Mid(MotAsp_Lib_SINCOS_LIMIT_DATA *MotAsp_Lib_Obj)
{
     MotAsp_Lib_Obj->Val = ( MotAsp_Lib_Obj->Max + MotAsp_Lib_Obj->Min ) >> 1U;
}

/*
*Function :                                MotAsp_Lib_UpdataMinMax              
*Brief    :     Query the collected values of sin, cos, or other trajectories compared with the 
               previous maximum and minimum values, and feedback the maximum and minimum values                  
*Para     :                   MotAsp_Lib_SIG_DIAG_BASIC_STATUS *MotAsp_Lib_Obj    
                                   typedef struct {
                                             sint16 Val;    -    The median value of the calculation
                                             sint16 Max;    -    maximum
                                             sint16 Min;    -    minmum
                                             }MotAsp_Lib_SINCOS_LIMIT_DATA;                      
*Return   :                                   NULL                              
 */
void MotAsp_Lib_UpdataMinMax(MotAsp_Lib_SINCOS_LIMIT_DATA *MotAsp_Lib_Obj)
{
     MotAsp_Lib_Obj->Max = ((int16_T)MotAsp_Lib_Obj->Val > MotAsp_Lib_Obj->Max ) ? (int16_T)MotAsp_Lib_Obj->Val : (int16_T)MotAsp_Lib_Obj->Max;

     MotAsp_Lib_Obj->Min = ((int16_T)MotAsp_Lib_Obj->Val < MotAsp_Lib_Obj->Min ) ? (int16_T)MotAsp_Lib_Obj->Val : (int16_T)MotAsp_Lib_Obj->Min;
}

/*
*Function :                                MotAsp_Lib_Cnt_UpdataMinMax                 
*Brief    :        Check whether the maximum and minimum values of the collection are updated,
               compare them with the size of the set limit center point to the amplitude, check whether 
               there is any exceedance, and record the number of times, status, and exceeded values                          
*Para     :                        MotAsp_Lib_SIG_DIAG_BASIC_STATUS *MotAsp_Lib_Obj 
                         typedef struct {
                                   sint16 Center_Point;                         -    Center point                  
                                   sint16 Amplitude;                            -    Amplitude

                                   MotAsp_Lib_SINCOS_LIMIT_DATA Interim;        -    The collected information and the maximum and minimum values  
                                   MotAsp_Lib_DATA_LIMIT_S16 Curr;              -    The current information and the maximum and minimum values ...   
                                   MotAsp_Lib_CNT_STATUS Updata_Max;            -    A count structure where the maximum value is exceeded           
                                   MotAsp_Lib_CNT_STATUS Updata_Min;            -    A count structure where the minimum value is exceeded                         
                                   uint16 sico_Beyong;                          -    The maximum and minimum simultaneous overrun status                         
                                   }MotAsp_Lib_SINCOS_CALC_MINMAX_ALGTH_STATUS;                                                           
*Return   :                                   NULL                                     
 */
void MotAsp_Lib_Cnt_UpdataMinMax(MotAsp_Lib_SINCOS_CALC_MINMAX_ALGTH_STATUS *MotAsp_Lib_Obj)
{
     MotAsp_Lib_Obj->sico_Beyong = MotAsp_Base_InValid;

     if(MotAsp_Lib_Obj->Interim.Min < (int16_T)(MotAsp_Lib_Obj->Center_Point - MotAsp_Lib_Obj->Amplitude))
     {
          MotAsp_Lib_Obj->Curr.Min = MotAsp_Lib_Obj->Interim.Min;
          MotAsp_Lib_Obj->Updata_Min.Sig = MotAsp_Base_Valid;

          if(MotAsp_Lib_Obj->Updata_Min.cnt >= MotAsp_Lib_Obj->Updata_Min.CNT)
          {
              MotAsp_Lib_Obj->Updata_Min.cnt = 0U;      
          }
          else
          {
               MotAsp_Lib_Obj->Updata_Min.cnt++;
          }
     }

     MotAsp_Lib_Obj->Interim.Min = MotAsp_Lib_Obj->Center_Point;

     if(MotAsp_Lib_Obj->Interim.Max > (int16_T)(MotAsp_Lib_Obj->Center_Point + MotAsp_Lib_Obj->Amplitude))
     {
          MotAsp_Lib_Obj->Curr.Max = MotAsp_Lib_Obj->Interim.Max;
          MotAsp_Lib_Obj->Updata_Max.Sig = MotAsp_Base_Valid;

          if(MotAsp_Lib_Obj->Updata_Max.cnt >= MotAsp_Lib_Obj->Updata_Max.CNT)
          {
              MotAsp_Lib_Obj->Updata_Max.cnt = 0U;      
          }
          else
          {
               MotAsp_Lib_Obj->Updata_Max.cnt++;
          }
     }

     MotAsp_Lib_Obj->Interim.Max = MotAsp_Lib_Obj->Center_Point;

     if((MotAsp_Base_Valid == MotAsp_Lib_Obj->Updata_Max.Sig) && (MotAsp_Base_Valid == MotAsp_Lib_Obj->Updata_Min.Sig))
     {
          MotAsp_Lib_Obj->sico_Beyong = MotAsp_Base_Valid;
     }
     else{
          MotAsp_Lib_Obj->sico_Beyong = MotAsp_Base_InValid;
     }
}

/*
*Function :                             MotAsp_Lib_Mps_Pi_Calc                      
*Brief    :              PI compensation algorithm for the maximum and minimum values of sin and cos                         
*Para     :              MotAsp_Lib_SINCOS_CALC_CENTER_INTERIM_STATUS *MotAsp_Lib_Obj        
                              typedef struct {
                              sint16 Calc_G;                        -     Gain
                              sint16 Calc_molecule0;                -     molecule-
                              sint16 Calc_numerator0;               -     denominator-

                              sint16 Simp;                          -     The maximum or minimum value of cos and sin
                              sint16 result;                        -     The result after compensation            
                              }MotAsp_Lib_SINCOS_CALC_CENTER_INTERIM_STATUS;                         
*Return   :                                   NULL                                      
 */    

void MotAsp_Lib_Mps_Pi_Calc(MotAsp_Lib_SINCOS_CALC_CENTER_INTERIM_STATUS *MotAsp_Lib_Obj)
{
     int32_T result;
     
     int32_T last_interim;
     int32_T diff;
 
     if(MotAsp_Base_Valid != MotAsp_Lib_Obj->Init_Sig)
     {
          MotAsp_Lib_Obj->Init_Sig = MotAsp_Base_Valid;
          last_interim = MotAsp_Lib_Obj->Simp * (int32_T)(MotAsp_Lib_Obj->Calc_G);
     }
     else
     {
          last_interim = MotAsp_Lib_Obj->Last_Simp;
     }

     diff = MotAsp_Lib_Obj->Simp - (int16_T)(last_interim / MotAsp_Lib_Obj->Calc_G);

     result = last_interim + ((diff * MotAsp_Lib_Obj->Calc_molecule0) / (MotAsp_Lib_Obj->Calc_numerator0));

     MotAsp_Lib_Obj->Last_Simp = result;
     
     MotAsp_Lib_Obj->result = (int16_T)(result / MotAsp_Lib_Obj->Calc_G);
}
/*
*Function :                                MotAsp_Lib_Mps_SimpleFault                 
*Brief    :               Diagnostic detection of the status of the four wires of sin+, sin-, cos+, and cos-                         
*Para     :               MotAsp_Lib_SIG_DIAG_BASIC_STATUS *MotAsp_Lib_Obj 
                              typedef struct{
                                   MotAsp_Lib_SIG_V_RANGE_TYPE V_Range;     -   The range of AD voltage values for the sin+, cos+, sin-, and cos- signals
                                   
                                   uint16 SinCos_V;                         -   Acquisition AD values of sin+, cos+, sin-, and cos- signals
                                   MotAsp_Lib_CNT_STATUS SiCo_F;            -   sin+, cos+, sin-, cos- signal counting structures
                              }MotAsp_Lib_SIG_DIAG_BASIC_STATUS;                            
*Return   :                                   NULL                                    
 */
 void MotAsp_Lib_Mps_SimpleFault(MotAsp_Lib_SIG_DIAG_BASIC_STATUS *MotAsp_Lib_Obj)
 {
     if(MotAsp_Lib_Obj->SinCos_V <= MotAsp_Lib_Obj->V_Range.Min_V)
     {
          if(MotAsp_Lib_Obj->SiCo_F.cnt > MotAsp_Lib_Obj->SiCo_F.CNT)
          {
               MotAsp_Lib_Obj->SiCo_F.Sig = MOTASP_Lib_F_SG;/*MOTASP_F_OP*/
          }
          else
          {
               MotAsp_Lib_Obj->SiCo_F.cnt++;
          }
     }
     else if(MotAsp_Lib_Obj->SinCos_V <= MotAsp_Lib_Obj->V_Range.Min_Allow)
     {
          if(MotAsp_Lib_Obj->SiCo_F.cnt > MotAsp_Lib_Obj->SiCo_F.CNT)
          {
               MotAsp_Lib_Obj->SiCo_F.Sig = MOTASP_Lib_F_ERR;
          }
          else
          {
               MotAsp_Lib_Obj->SiCo_F.cnt++;
          }
     }
     else if(MotAsp_Lib_Obj->SinCos_V >= MotAsp_Lib_Obj->V_Range.Max_Allow)
     {
          if(MotAsp_Lib_Obj->SiCo_F.cnt > MotAsp_Lib_Obj->SiCo_F.CNT)
          {
               MotAsp_Lib_Obj->SiCo_F.Sig = MOTASP_Lib_F_ERR;
          }
          else
          {
               MotAsp_Lib_Obj->SiCo_F.cnt++;
          }
     }
     else if(MotAsp_Lib_Obj->SinCos_V >= MotAsp_Lib_Obj->V_Range.Max_V)
     {
          if(MotAsp_Lib_Obj->SiCo_F.cnt > MotAsp_Lib_Obj->SiCo_F.CNT)
          {
               MotAsp_Lib_Obj->SiCo_F.Sig = MOTASP_Lib_F_SB;
          }
          else
          {
               MotAsp_Lib_Obj->SiCo_F.cnt++;
          }
     }
     else
     {
          MotAsp_Lib_Obj->SiCo_F.cnt = 0U;
          MotAsp_Lib_Obj->SiCo_F.Sig = MOTASP_Lib_F_NORMAL;
     }
 }

 /*
*Function :                                MotAsp_Lib_Mps_SiNCos_Calib             
*Brief    :     Diagnostic detection of the status of the four wires of sin,  cos,                    
*Para     :     MotAsp_Lib_SINCOS_CALIB_BASIC_STATUS *MotAsp_Lib_Obj               
                    typedef struct{
                    MotAsp_Lib_SINCOS_CALIB_PARA_STATUS Limit_D;    -     sin, cos signal counting structures 
                    
                    MotAsp_Lib_SinCos_INFO SiCo_Diff;               -     SIN and COS signals     
                    MotAsp_Lib_CNT_STATUS SiCs_DF;                  -     Acquisition AD values of sin+, cos, sin,                                                                      
               }MotAsp_Lib_SINCOS_CALIB_BASIC_STATUS;                 
*Return   :                                   NULL                                 
 */
void MotAsp_Lib_Mps_SiNCos_Calib(MotAsp_Lib_SINCOS_CALIB_BASIC_STATUS *MotAsp_Lib_Obj)
{
    if((MotAsp_Lib_Obj->SiCo_Diff.Cos > (MotAsp_Lib_Obj->Limit_D.Limit_Mid - MotAsp_Lib_Obj->Limit_D.Diff_V))\
        &&(MotAsp_Lib_Obj->SiCo_Diff.Cos < (MotAsp_Lib_Obj->Limit_D.Limit_Mid + MotAsp_Lib_Obj->Limit_D.Diff_V))){
        
        if(((MotAsp_Lib_Obj->SiCo_Diff.Sin < MotAsp_Lib_Obj->Limit_D.Limit_Max)&&(MotAsp_Lib_Obj->SiCo_Diff.Sin > MotAsp_Lib_Obj->Limit_D.Limit_Mid))||\
            ((MotAsp_Lib_Obj->SiCo_Diff.Cos > MotAsp_Lib_Obj->Limit_D.Limit_Min)&&(MotAsp_Lib_Obj->SiCo_Diff.Cos < MotAsp_Lib_Obj->Limit_D.Limit_Mid)))
        {
            if(MotAsp_Lib_Obj->SiCs_DF.cnt >= MotAsp_Lib_Obj->SiCs_DF.CNT)
            {
                MotAsp_Lib_Obj->SiCs_DF.cnt = MotAsp_Lib_Obj->SiCs_DF.CNT;
                MotAsp_Lib_Obj->SiCs_DF.Sig = MotAsp_Base_Valid;
            }
            else
            {
               MotAsp_Lib_Obj->SiCs_DF.cnt++;
            }
        }
    }
    else if((MotAsp_Lib_Obj->SiCo_Diff.Sin > (MotAsp_Lib_Obj->Limit_D.Limit_Mid - MotAsp_Lib_Obj->Limit_D.Diff_V))\
        &&(MotAsp_Lib_Obj->SiCo_Diff.Sin < (MotAsp_Lib_Obj->Limit_D.Limit_Mid + MotAsp_Lib_Obj->Limit_D.Diff_V))){
        
        if(((MotAsp_Lib_Obj->SiCo_Diff.Cos < MotAsp_Lib_Obj->Limit_D.Limit_Max)&&(MotAsp_Lib_Obj->SiCo_Diff.Cos > MotAsp_Lib_Obj->Limit_D.Limit_Mid))||\
            ((MotAsp_Lib_Obj->SiCo_Diff.Sin > MotAsp_Lib_Obj->Limit_D.Limit_Min)&&(MotAsp_Lib_Obj->SiCo_Diff.Sin < MotAsp_Lib_Obj->Limit_D.Limit_Mid)))
        {
            if(MotAsp_Lib_Obj->SiCs_DF.cnt >= MotAsp_Lib_Obj->SiCs_DF.CNT)
            {
                MotAsp_Lib_Obj->SiCs_DF.cnt = MotAsp_Lib_Obj->SiCs_DF.CNT;
                MotAsp_Lib_Obj->SiCs_DF.Sig = MotAsp_Base_Valid;
            }
            else
            {
               MotAsp_Lib_Obj->SiCs_DF.cnt++;
            }
        }
    }
    else{
        MotAsp_Lib_Obj->SiCs_DF.Sig = MotAsp_Base_InValid;
        MotAsp_Lib_Obj->SiCs_DF.cnt = 0U;
    }
}

 /*
*Function :                  MotAsp_Lib_Mps_SinCos_Simp_Mid_Avg_Filter                         
*Brief    :         Sin+ and Sin-, Cos+ and Cos- signals are synthesized into Sin, CoS, and the Sin or CoS signals are obtained by backup and processing
*Para     :         MotAsp_Lib_SINCOS_SIMP_MID_AVG_FILTE_STAUTS *MotAsp_Lib_Obj: 
                              typedef struct {
                                   sint16 Calc_Gain;                 -     Sin and Cos collect and calculate the magnification or gain of the original signal
                                   uint16 Simp_Arr_CNT;              -     The length of the array
                                   sint16 *Simp_Arr_Dislay;          -     The pointer to the signal history data array of Sin and Cos 

                                   uint16 Limit_Calib;               -     Effective limits for Sin+, Cos+, Sin-, Cos-
                                   uint16 State;                     -     The signal validity status of Sin+, Cos+, Sin-, and Cos-
                                   uint16 Simp0;                     -     Sin-、Cos-
                                   uint16 Simp1;                     -     Sin+、Cos+
                                   sint16 Simp;                      -     Sin、Cos ；For example : Simp_Sin = Gain * (Sin+ - Sin-);
                                   sint16 Simp_Last;                 -     The Sin、Cos result of the last Simp
                                   uint16 Simp_Arr_Cnt;              -     The length of the array
                                   sint16 FILTER;                    -     The Sin、Cos current filtering results
                              }MotAsp_Lib_SINCOS_SIMP_MID_AVG_FILTE_STAUTS;                         
*Return   :                                  NULL                                                
 */

void MotAsp_Lib_Mps_SinCos_Simp_Mid_Avg_Filter(MotAsp_Lib_SINCOS_SIMP_MID_AVG_FILTE_STAUTS *MotAsp_Lib_Obj)
{
     int16_T filter_max = 0;
     int16_T filter_min = 0;

     volatile int64_T sico_sum = 0;

     if((MotAsp_Lib_Obj->Simp0 < MotAsp_Lib_Obj->Limit_Calib) ||(MotAsp_Lib_Obj->Simp1 < MotAsp_Lib_Obj->Limit_Calib))
     {
          MotAsp_Lib_Obj->Simp = MotAsp_Lib_Obj->Simp_Last;
          MotAsp_Lib_Obj->State = MotAsp_Base_InValid;
     }
     else
     {
          MotAsp_Lib_Obj->Simp = (int16_T)(MotAsp_Lib_Obj->Calc_Gain * (MotAsp_Lib_Obj->Simp1 - MotAsp_Lib_Obj->Simp0));
          MotAsp_Lib_Obj->Simp_Last = MotAsp_Lib_Obj->Simp;
          MotAsp_Lib_Obj->State = MotAsp_Base_Valid;
     }

     if(MotAsp_Lib_Obj->Simp_Arr_Cnt < MotAsp_Lib_Obj->Simp_Arr_CNT)
     {
          MotAsp_Lib_Obj->Simp_Arr_Dislay[MotAsp_Lib_Obj->Simp_Arr_Cnt] = MotAsp_Lib_Obj->Simp;
          MotAsp_Lib_Obj->FILTER = MotAsp_Lib_Obj->Simp;

          MotAsp_Lib_Obj->Simp_Arr_Cnt++;
     }
     else
     {
          filter_max = MotAsp_Lib_Obj->Simp;
          filter_min = MotAsp_Lib_Obj->Simp;
          
          for(uint16_T i = 0u ; i < (uint16_T)MotAsp_Lib_Obj->Simp_Arr_CNT ; i++)
          {
               if(MotAsp_Lib_Obj->Simp_Arr_Dislay[i] > filter_max)
               {
                    filter_max = MotAsp_Lib_Obj->Simp_Arr_Dislay[i];
               }
               else if(MotAsp_Lib_Obj->Simp_Arr_Dislay[i] < filter_min)
               {
                    filter_min = MotAsp_Lib_Obj->Simp_Arr_Dislay[i];
               }

               sico_sum += MotAsp_Lib_Obj->Simp_Arr_Dislay[i];

               if(i < (uint16_T)(MotAsp_Lib_Obj->Simp_Arr_CNT - 1U))
               {
                    MotAsp_Lib_Obj->Simp_Arr_Dislay[i] = MotAsp_Lib_Obj->Simp_Arr_Dislay[i + 1U];
               }
               else{
                    MotAsp_Lib_Obj->Simp_Arr_Dislay[i] = MotAsp_Lib_Obj->Simp;
               }
          }

          MotAsp_Lib_Obj->FILTER = (int16_T)((int32_T)((MotAsp_Lib_Obj->Simp + sico_sum) - \
                                             filter_max -  filter_min)/(int32_T)(MotAsp_Lib_Obj->Simp_Arr_CNT - 1U));
     }
}

/*
*Function :                   MotAsp_Lib_Mps_SinCos_Calib_Logic                               
*Brief    :         The maximum and minimum values of sin(cos) are calculated by cos(sin), and the 
          center point and gain are calculated, and the proportional values of the current sin(cos) are obtained
*Para     :         MotAsp_Lib_SINCOS_SIMP_MID_AVG_FILTE_STAUTS *MotAsp_Lib_Obj:   
                         typedef struct {
                         uint16 Ratio;                                      -   The value of a quarter of each circle, such as:65536 / 4 = 16384
                         MotAsp_Lib_SINCOS_LIMIT_DATA Init;                 -   The initial maximum and minimum values of sin(cos).  
                         uint16 Arr_CNT;                                    -   How much of this data is prepared is calculated after that 

                         sint16 Simp;                                       -   sin(cos) is the current value of the collection                                 
                         MotAsp_Lib_CALI_STATE State;                       -   Operational status                                 
                         sint16 Simp_Another;                               -   cos(sin), the signal variable used for reference by the signal under test               
                         uint16 Arr_Cnt;                                    -   The number of times the current count is counted                
                         MotAsp_Lib_SINCOS_CALC_MINMAX_ALGTH_STATUS MIA;    -   Detects the maximum or minimum value of the signal's sin(cos).             
                         MotAsp_Lib_SINCOS_CALC_CENTER_INTERIM_STATUS max;  -   The maximum value of this signal sin(cos) is the PI structure             
                         MotAsp_Lib_SINCOS_CALC_CENTER_INTERIM_STATUS min;  -   The minimum value of this signal sin(cos) is the PI structure 
                         sint16 Center;                                     -     Center point 
                         sint16 Result;                                     -   The correction algorithm calculates the value of the sin(cos) signal                                      
                         }MotAsp_Lib_SINCOS_CALC_LOGIC_STATUS;                  
*Return   :                                   NULL                                              
 */
void MotAsp_Lib_Mps_SinCos_Calib_Logic(MotAsp_Lib_SINCOS_CALC_LOGIC_STATUS *MotAsp_Lib_Obj , MotAsp_Lib_SINCOS_CALC_LOGIC_STATUS *MotAsp_Lib_Refer)
{
     int16_T basic = 0;

     switch(MotAsp_Lib_Obj->State)
     {
          case MotAsp_Lib_CALI_IDLE:
               MotAsp_Lib_Obj->MIA.Curr.Max = MotAsp_Lib_Obj->Init.Max;
               MotAsp_Lib_Obj->MIA.Curr.Min = MotAsp_Lib_Obj->Init.Min;

               MotAsp_Lib_Obj->MIA.Interim.Min = MotAsp_Lib_Obj->MIA.Center_Point;
               MotAsp_Lib_Obj->MIA.Interim.Max = MotAsp_Lib_Obj->MIA.Center_Point;
               MotAsp_Lib_Obj->State = MotAsp_Lib_CALI_START;
          break;
          case MotAsp_Lib_CALI_START:
               if(MotAsp_Lib_Obj->Arr_Cnt > MotAsp_Lib_Obj->Arr_CNT)
               {
                    if(MotAsp_Lib_Refer->MIA.Interim.Val > (int16_T)(MotAsp_Lib_Refer->Simp_Another + MotAsp_Lib_Refer->MIA.Amplitude))
                    {
                          MotAsp_Lib_Obj->State = MotAsp_Lib_CALI_CCURVE_PEAK;
                    }

                    if(MotAsp_Lib_Refer->MIA.Interim.Val < (int16_T)(MotAsp_Lib_Refer->Simp_Another - MotAsp_Lib_Refer->MIA.Amplitude))
                    {
                         MotAsp_Lib_Obj->State = MotAsp_Lib_CALI_CCURVE_VELLEY;
                    }
               }
               else
               {
                    MotAsp_Lib_Obj->Arr_Cnt++;
               }
          break;
          case MotAsp_Lib_CALI_CCURVE_PEAK:

               if(MotAsp_Lib_Refer->MIA.Interim.Val < (int16_T)(MotAsp_Lib_Refer->Simp_Another + MotAsp_Lib_Refer->MIA.Amplitude))
               {
                    MotAsp_Lib_Obj->State = MotAsp_Lib_CALI_CCURVE_DOWN;
               }
          break;
          case MotAsp_Lib_CALI_CCURVE_DOWN:
               if(MotAsp_Lib_Refer->MIA.Interim.Val < (int16_T)(MotAsp_Lib_Refer->Simp_Another - MotAsp_Lib_Refer->MIA.Amplitude))
               {
                    MotAsp_Lib_Cnt_UpdataMinMax(&(MotAsp_Lib_Obj->MIA));
                     MotAsp_Lib_Obj->State = MotAsp_Lib_CALI_CCURVE_VELLEY;
               }
               else if(MotAsp_Lib_Refer->MIA.Interim.Val > (int16_T)(MotAsp_Lib_Refer->Simp_Another + MotAsp_Lib_Refer->MIA.Amplitude))
               {
                    MotAsp_Lib_Obj->MIA.Interim.Min = MotAsp_Lib_Obj->MIA.Center_Point;
                    MotAsp_Lib_Obj->MIA.Interim.Max = MotAsp_Lib_Obj->MIA.Center_Point;
                    MotAsp_Lib_Obj->State = MotAsp_Lib_CALI_CCURVE_PEAK;
               }
               else{
                    MotAsp_Lib_UpdataMinMax(&(MotAsp_Lib_Obj->MIA.Interim));
               }
          break;
          case MotAsp_Lib_CALI_CCURVE_UP:
               if(MotAsp_Lib_Refer->MIA.Interim.Val > (int16_T)(MotAsp_Lib_Refer->Simp_Another + MotAsp_Lib_Refer->MIA.Amplitude))
               {
                    MotAsp_Lib_Cnt_UpdataMinMax(&(MotAsp_Lib_Obj->MIA));
                     MotAsp_Lib_Obj->State = MotAsp_Lib_CALI_CCURVE_PEAK;
               }
               else if(MotAsp_Lib_Refer->MIA.Interim.Val < (int16_T)(MotAsp_Lib_Refer->Simp_Another - MotAsp_Lib_Refer->MIA.Amplitude))
               {
                    MotAsp_Lib_Obj->MIA.Interim.Min = MotAsp_Lib_Obj->MIA.Center_Point;
                    MotAsp_Lib_Obj->MIA.Interim.Max = MotAsp_Lib_Obj->MIA.Center_Point;
                    MotAsp_Lib_Obj->State = MotAsp_Lib_CALI_CCURVE_VELLEY;
               }
               else{
                    MotAsp_Lib_UpdataMinMax(&(MotAsp_Lib_Obj->MIA.Interim));
               }
          break;
          case MotAsp_Lib_CALI_CCURVE_VELLEY:
          default:
               if(MotAsp_Lib_Refer->MIA.Interim.Val > (int16_T)(MotAsp_Lib_Refer->Simp_Another - MotAsp_Lib_Refer->MIA.Amplitude))
               {
                    MotAsp_Lib_Obj->State = MotAsp_Lib_CALI_CCURVE_UP;
               }
          break;
     }

     if(MotAsp_Base_Valid != MotAsp_Lib_Obj->Init_Sig)
     {
          MotAsp_Lib_Obj->Init_Sig = MotAsp_Base_Valid;
          MotAsp_Lib_Obj->Offer = (int16_T)((MotAsp_Lib_Obj->Init.Max + MotAsp_Lib_Obj->Init.Min) >> 1U);
          MotAsp_Lib_Obj->Gain = (int16_T)((MotAsp_Lib_Obj->Init.Max - MotAsp_Lib_Obj->Init.Min) >> 1U);
     }
     
     MotAsp_Lib_Obj->max.Simp = MotAsp_Lib_Obj->MIA.Curr.Max;
     MotAsp_Lib_Obj->min.Simp = MotAsp_Lib_Obj->MIA.Curr.Min;

     MotAsp_Lib_Obj->Pi_Clac_En = MotAsp_Lib_Obj->MIA.sico_Beyong;

     if(MotAsp_Base_Valid == MotAsp_Lib_Obj->Pi_Clac_En)
     {
          MotAsp_Lib_Obj->Pi_Clac_En = MotAsp_Base_InValid;
          MotAsp_Lib_Obj->MIA.sico_Beyong = MotAsp_Base_InValid;
          MotAsp_Lib_Obj->MIA.Updata_Max.Sig = MotAsp_Base_InValid;
          MotAsp_Lib_Obj->MIA.Updata_Min.Sig = MotAsp_Base_InValid;

          MotAsp_Lib_Mps_Pi_Calc(&(MotAsp_Lib_Obj->max));
          MotAsp_Lib_Mps_Pi_Calc(&(MotAsp_Lib_Obj->min));   
          
          MotAsp_Lib_Obj->Offer = (int16_T)((MotAsp_Lib_Obj->max.result + MotAsp_Lib_Obj->min.result) >> 1U);
          MotAsp_Lib_Obj->Gain = (int16_T)((MotAsp_Lib_Obj->max.result - MotAsp_Lib_Obj->min.result) >> 1U);
     }
     
     basic = (int16_T)(MotAsp_Lib_Obj->Simp - MotAsp_Lib_Obj->Offer);

     MotAsp_Lib_Obj->Center = MotAsp_Lib_Obj->Offer;

     MotAsp_Lib_Obj->Result = (int16_T)((int32_T)(basic * (int16_T)MotAsp_Lib_Obj->Ratio) / MotAsp_Lib_Obj->Gain);
}

/*
*Function :                   MotAsp_Lib_Mps_Find_Coordinates                                 
*Brief    :         The angular signal value calculated by tangent 
*Para     :         MotAsp_Lib_SINCOS_TRACK_COORDINATE_STATUS *MotAsp_Lib_Obj: 
                         typedef struct {
                              uint16 ArcTan45_Arr_Num;                                -   The size of the tangent array                                      
                              uint16 Degrees_90;                                      -   What is the value of 90° 
                                     
                              MotAsp_Lib_SinCos_INFO Calib;                           -   Corrected SIN and COS signals                       
                              MotAsp_Lib_COORDINATE_BASIC_ANGLE_STATE Basic;          -   The starting value of the x,y axis of the trajectory circle                                                
                              uint8 Quadrant;                                         -   Quadrants of the x-and y-axis of the trajectory circle                       
                              uint16 Angle;                                           -   The calculated angle                                          
                         }MotAsp_Lib_SINCOS_TRACK_COORDINATE_STATUS;                       
*Return   :                                   NULL                                             
 */
void MotAsp_Lib_Mps_Find_Coordinates(MotAsp_Lib_SINCOS_TRACK_COORDINATE_STATUS *MotAsp_Lib_Obj)
{
     uint8_T quadrant = 0u;
     uint16_T basic_val = 0u;
     MotAsp_Lib_SinCos_INFO interim;
     uint8_T quadrant_sig = MotAsp_Base_InValid;
     uint16_T arctan_index = 0u;

     if(MotAsp_Lib_Obj->Calib.Sin >= 0)
     {

          quadrant = MotAsp_Lib_COORDINATE_BASIC0;
          
          if(MotAsp_Lib_Obj->Calib.Sin == 0)
          {
               quadrant = MotAsp_Lib_COORDINATE_BASIC1;
          }
     }

     if(MotAsp_Lib_Obj->Calib.Cos >= 0)
     {

          quadrant += MotAsp_Lib_COORDINATE_BASIC2;

          if(MotAsp_Lib_Obj->Calib.Cos == 0)
          {
               quadrant += MotAsp_Lib_COORDINATE_BASIC3;
          }
     }

     switch(quadrant)
     {
          case MotAsp_Lib_COORDINATE_QUADI:
               quadrant_sig = MotAsp_Base_Valid;
               basic_val = MotAsp_Lib_Obj->Basic.Quad_I;
               interim.Sin = MotAsp_Lib_Obj->Calib.Cos;
               interim.Cos = MotAsp_Lib_Obj->Calib.Sin;
          break;
          case MotAsp_Lib_COORDINATE_QUADII:
               quadrant_sig = MotAsp_Base_Valid;
               basic_val = MotAsp_Lib_Obj->Basic.Quad_II;
               interim.Sin = (int16_T)(0 -MotAsp_Lib_Obj->Calib.Sin);
               interim.Cos = MotAsp_Lib_Obj->Calib.Cos;
          break;
          case MotAsp_Lib_COORDINATE_QUADIII:
               quadrant_sig = MotAsp_Base_Valid;
               basic_val = MotAsp_Lib_Obj->Basic.Quad_III;
               interim.Sin = (int16_T)(0 -MotAsp_Lib_Obj->Calib.Cos);
               interim.Cos = (int16_T)(0 -MotAsp_Lib_Obj->Calib.Sin);
          break;
          case MotAsp_Lib_COORDINATE_QUADIV:
               quadrant_sig = MotAsp_Base_Valid;
               basic_val = MotAsp_Lib_Obj->Basic.Quad_IV;
               interim.Sin = (MotAsp_Lib_Obj->Calib.Sin);
               interim.Cos = (int16_T)(0 - MotAsp_Lib_Obj->Calib.Cos);
          break;
          case MotAsp_Lib_COORDINATE_NORTH:
               basic_val = MotAsp_Lib_Obj->Basic.Quad_II;
          break;
          case MotAsp_Lib_COORDINATE_SOUTH:
               basic_val = MotAsp_Lib_Obj->Basic.Quad_IV;
          break;
          case MotAsp_Lib_COORDINATE_WEST:
               basic_val = MotAsp_Lib_Obj->Basic.Quad_III;
          break;
          case MotAsp_Lib_COORDINATE_EAST:
          break;
          case MotAsp_Lib_COORDINATE_CENTER:
          break;
          default :
          break;
     }

     if(quadrant_sig == MotAsp_Base_Valid)
     {
          if(interim.Cos > interim.Sin)
          {
               arctan_index = (uint16_T)(MotAsp_Lib_Obj->ArcTan45_Arr_Num * interim.Sin / interim.Cos);
          
               if(arctan_index >= MotAsp_Lib_Obj->ArcTan45_Arr_Num)
               {
                    arctan_index = MotAsp_Lib_Obj->ArcTan45_Arr_Num - 1U;
               }

               MotAsp_Lib_Obj->Angle_Comp = MOTASP_Lib_AtanTable[arctan_index];
          }
          else
          {
               arctan_index = (uint16_T)(MotAsp_Lib_Obj->ArcTan45_Arr_Num * interim.Cos / interim.Sin);

               if(arctan_index >= MotAsp_Lib_Obj->ArcTan45_Arr_Num)
               {
                    arctan_index = MotAsp_Lib_Obj->ArcTan45_Arr_Num - 1U;
               }

               MotAsp_Lib_Obj->Angle_Comp = MotAsp_Lib_Obj->Degrees_90 -  MOTASP_Lib_AtanTable[arctan_index];  
          }

          MotAsp_Lib_Obj->Angle = (uint16_T)((int32_T)MotAsp_Lib_Obj->Angle_Comp + basic_val);
     }
     else
     {
          MotAsp_Lib_Obj->Angle = basic_val;
     }

     MotAsp_Lib_Obj->Baisc_V = basic_val;
     MotAsp_Lib_Obj->Quadrant = quadrant;
}

/*
*Function :                   MotAsp_Lib_Mps_E_Angle_Spd_Increment_Calc                                   
*Brief    :         Calculate the corresponding amount of angle accumulation as well as the velocity of the angle 
*Para     :         MotAsp_Lib_ANGLE_INCREMENT_STAUTS *MotAsp_Lib_Obj:    
                         typedef struct {
                              uint16 Degrees_180;     -     What is the value of 180°             
                              uint16 Degrees_360;     -     What is the value of 360° 
                         
                              uint16 Calib_Angle;     -     The calculated angle                                                 
                              sint32 Incr_Angle;      -     The value that increases each time                                                             
                              sint64 Angle;           -     All angles increase and                                              
                              sint64 Last_Angle;      -     The Angle value of the last time                                                   
                              sint32 spd;             -     Angles that increase with each run                                                                            
                              }MotAsp_Lib_ANGLE_INCREMENT_STAUTS;                     
*Return   :                                  NULL                                                
 */
void MotAsp_Lib_Mps_E_Angle_Spd_Increment_Calc(MotAsp_Lib_ANGLE_INCREMENT_STAUTS *MotAsp_Lib_Obj)
{
     int32_T interim_incr = 0;
     int16_T interim_spd = 0;
     
     interim_incr = (MotAsp_Lib_Obj->Calib_Angle - MotAsp_Lib_Obj->Last_Calib_Angle);

     if(MotAsp_Lib_Obj->Calib_Angle > MotAsp_Lib_Obj->Last_Calib_Angle)
     {
          if(interim_incr < ((uint16_T)(MotAsp_Lib_Obj->Degrees_180)))
          {
               MotAsp_Lib_Obj->Incr_Angle = interim_incr;
          }
          else
          {
               MotAsp_Lib_Obj->Incr_Angle = interim_incr - ((uint16_T)MotAsp_Lib_Obj->Degrees_360);
          }
     }
     else
     {
          if(interim_incr > (-(uint16_T)MotAsp_Lib_Obj->Degrees_180))
          {
               MotAsp_Lib_Obj->Incr_Angle = interim_incr;
          }
          else
          {
               MotAsp_Lib_Obj->Incr_Angle = interim_incr + ((uint16_T)MotAsp_Lib_Obj->Degrees_360);
          }
     }

     MotAsp_Lib_Obj->Angle = (int32_T)(MotAsp_Lib_Obj->Delay0_Angle + MotAsp_Lib_Obj->Incr_Angle);

     
     if(MotAsp_Lib_Obj->Init_Sig != MotAsp_Base_Valid)
     {
          MotAsp_Lib_Obj->Init_Sig = MotAsp_Base_Valid;
          interim_spd = 0;
     }
     else
     {
          interim_spd = (int16_T)((int32_T)(MotAsp_Lib_Obj->Angle - MotAsp_Lib_Obj->Delay0_Angle) + \
                         3 * (MotAsp_Lib_Obj->Delay0_Angle - MotAsp_Lib_Obj->Delay1_Angle) + \
                         (MotAsp_Lib_Obj->Delay1_Angle - MotAsp_Lib_Obj->Delay2_Angle)) / 5;                         
     }

     MotAsp_Lib_Obj->Last_Calib_Angle = MotAsp_Lib_Obj->Calib_Angle;
  
     MotAsp_Lib_Obj->spd = interim_spd;
     
     MotAsp_Lib_Obj->Delay2_Angle = MotAsp_Lib_Obj->Delay1_Angle;
     MotAsp_Lib_Obj->Delay1_Angle = MotAsp_Lib_Obj->Delay0_Angle;
     MotAsp_Lib_Obj->Delay0_Angle = MotAsp_Lib_Obj->Angle;

     MotAsp_Lib_Obj->M_Angle = (uint16_T)(MotAsp_Lib_Obj->Angle / MotAsp_Lib_Obj->Poles);

}


/*
*Function :                   MotAsp_Lib_MPS_STAUTS                              
*Brief    :         MPS throughout the process
*Para     :         MotAsp_Lib_SINCOS_SIMP_MID_AVG_FILTE_STAUTS *MotAsp_Lib_Obj: 
                         typedef struct {
                              MotAsp_Lib_SIG_DIAG_BASIC_STATUS D_SiCo_i[MotAsp_Lib_SIN_COS_SIG_NUM];    -    Diagnose the status of the sensor signal 
                              MotAsp_Lib_SINCOS_CALIB_BASIC_STATUS D_sic;                               -    Diagnose the status of the cos 、sin INFO    
                              MotAsp_Lib_SINCOS_SIMP_MID_AVG_FILTE_STAUTS F_Sico[MotAsp_Lib_SiCo_NUM];  -    Differential filtering of sensor signals                                                                
                              MotAsp_Lib_SINCOS_CALC_LOGIC_STATUS C_SiCo[MotAsp_Lib_SiCo_NUM];          -    Compensation of sensor signals                                                                    
                              MotAsp_Lib_SINCOS_TRACK_COORDINATE_STATUS Arctan;                         -    The arctangent of the sensor signal                                                           
                              MotAsp_Lib_ANGLE_INCREMENT_STAUTS Sp;                                     -    The velocity of the sensor signal as well as the position signal are calculated                                       
                              }MotAsp_Lib_MPS_STAUTS;                  
*Return   :                                   NULL                                       
 */
void MotAsp_Lib_Mps_Handler(MotAsp_Lib_MPS_STAUTS *MotAsp_Lib_Obj)
{
     uint8_T sin_allow = MotAsp_Base_Valid;
     uint8_T cos_allow = MotAsp_Base_Valid;

     for(uint8_T sico_i = 0U ; sico_i < MotAsp_Lib_SIN_COS_SIG_NUM ; sico_i++)
     {
          MotAsp_Lib_Mps_SimpleFault(&(MotAsp_Lib_Obj->D_SiCo_i[sico_i]));
     }

     MotAsp_Lib_Obj->F_Sico[MotAsp_Lib_SiCo_Sin].Simp0 = MotAsp_Lib_Obj->D_SiCo_i[MotAsp_Lib_SIN_0].SinCos_V;
     MotAsp_Lib_Obj->F_Sico[MotAsp_Lib_SiCo_Sin].Simp1 = MotAsp_Lib_Obj->D_SiCo_i[MotAsp_Lib_SIN_1].SinCos_V;
     MotAsp_Lib_Obj->F_Sico[MotAsp_Lib_SiCo_Cos].Simp0 = MotAsp_Lib_Obj->D_SiCo_i[MotAsp_Lib_COS_0].SinCos_V;
     MotAsp_Lib_Obj->F_Sico[MotAsp_Lib_SiCo_Cos].Simp1 = MotAsp_Lib_Obj->D_SiCo_i[MotAsp_Lib_COS_1].SinCos_V;

     MotAsp_Lib_Mps_SinCos_Simp_Mid_Avg_Filter(&(MotAsp_Lib_Obj->F_Sico[MotAsp_Lib_SiCo_Sin]));
     MotAsp_Lib_Mps_SinCos_Simp_Mid_Avg_Filter(&(MotAsp_Lib_Obj->F_Sico[MotAsp_Lib_SiCo_Cos]));

     MotAsp_Lib_Obj->D_sico.SiCo_Diff.Sin = MotAsp_Lib_Obj->F_Sico[MotAsp_Lib_SiCo_Sin].Simp;
     MotAsp_Lib_Obj->D_sico.SiCo_Diff.Cos = MotAsp_Lib_Obj->F_Sico[MotAsp_Lib_SiCo_Cos].Simp;
     MotAsp_Lib_Mps_SiNCos_Calib(&(MotAsp_Lib_Obj->D_sico));
     
     sin_allow = (uint8_T)(MotAsp_Lib_Obj->F_Sico[MotAsp_Lib_SiCo_Sin].State);
     cos_allow = (uint8_T)(MotAsp_Lib_Obj->F_Sico[MotAsp_Lib_SiCo_Cos].State);

     if((MotAsp_Base_Valid == sin_allow)&&(MotAsp_Base_Valid == cos_allow))
     {


          if(MotAsp_Base_Valid != MotAsp_Lib_Obj->Init_Sig)
          {
               MotAsp_Lib_Obj->Init_Sig = MotAsp_Base_Valid;          
               MotAsp_Lib_Com_Avg_Mid(&(MotAsp_Lib_Obj->C_SiCo[MotAsp_Lib_SiCo_Sin].Init));
               MotAsp_Lib_Com_Avg_Mid(&(MotAsp_Lib_Obj->C_SiCo[MotAsp_Lib_SiCo_Cos].Init));



               MotAsp_Lib_Obj->C_SiCo[MotAsp_Lib_SiCo_Sin].Simp_Another = MotAsp_Lib_Obj->C_SiCo[MotAsp_Lib_SiCo_Sin].Init.Val;
               MotAsp_Lib_Obj->C_SiCo[MotAsp_Lib_SiCo_Cos].Simp_Another = MotAsp_Lib_Obj->C_SiCo[MotAsp_Lib_SiCo_Cos].Init.Val;
          }
          else
          {
               MotAsp_Lib_Obj->C_SiCo[MotAsp_Lib_SiCo_Sin].Simp_Another = MotAsp_Lib_Obj->C_SiCo[MotAsp_Lib_SiCo_Sin].Center;
               MotAsp_Lib_Obj->C_SiCo[MotAsp_Lib_SiCo_Cos].Simp_Another = MotAsp_Lib_Obj->C_SiCo[MotAsp_Lib_SiCo_Cos].Center;
          }
          
          MotAsp_Lib_Obj->C_SiCo[MotAsp_Lib_SiCo_Cos].Simp = MotAsp_Lib_Obj->F_Sico[MotAsp_Lib_SiCo_Cos].Simp;
          MotAsp_Lib_Obj->C_SiCo[MotAsp_Lib_SiCo_Cos].MIA.Interim.Val = MotAsp_Lib_Obj->F_Sico[MotAsp_Lib_SiCo_Cos].FILTER; 
          MotAsp_Lib_Obj->C_SiCo[MotAsp_Lib_SiCo_Sin].Simp = MotAsp_Lib_Obj->F_Sico[MotAsp_Lib_SiCo_Sin].Simp;
          MotAsp_Lib_Obj->C_SiCo[MotAsp_Lib_SiCo_Sin].MIA.Interim.Val = MotAsp_Lib_Obj->F_Sico[MotAsp_Lib_SiCo_Sin].FILTER; 

          MotAsp_Lib_Mps_SinCos_Calib_Logic(&(MotAsp_Lib_Obj->C_SiCo[MotAsp_Lib_SiCo_Sin]) , &(MotAsp_Lib_Obj->C_SiCo[MotAsp_Lib_SiCo_Cos]));
          MotAsp_Lib_Mps_SinCos_Calib_Logic(&(MotAsp_Lib_Obj->C_SiCo[MotAsp_Lib_SiCo_Cos]) , &(MotAsp_Lib_Obj->C_SiCo[MotAsp_Lib_SiCo_Sin]));
          

          MotAsp_Lib_Obj->Arctan.Calib.Sin = MotAsp_Lib_Obj->C_SiCo[MotAsp_Lib_SiCo_Sin].Result;
          MotAsp_Lib_Obj->Arctan.Calib.Cos = MotAsp_Lib_Obj->C_SiCo[MotAsp_Lib_SiCo_Cos].Result;

          MotAsp_Lib_Mps_Find_Coordinates(&(MotAsp_Lib_Obj->Arctan));

          MotAsp_Lib_Obj->Sp.Calib_Angle =  MotAsp_Lib_Obj->Arctan.Angle;

          MotAsp_Lib_Mps_E_Angle_Spd_Increment_Calc(&(MotAsp_Lib_Obj->Sp));
     }
     else{

     }
}


